// 递归+ 前缀和
//输入一行字符串, f3@d5a8, 转为数字
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let initArr = [];
rl.on("line", (line)=>{
    if(initArr.length === 0) {

        initArr = line.trim().split("").map(char => char.charCodeAt(0))
        console.log(getResult(initArr))
        // clear
        initArr.length = 0
    }
})

function getResult(initArr) {
    // 前缀和
    let preSum = [0]
    for (const num of initArr) {
        preSum.push(preSum.at(-1) + num)
    }

    let result = []
    let map = new Map()
    dfs(0, initArr, preSum, result, map, 0)

    // 判断result的长度
    if(result.length === 0) {
        return 0
    } else if(result.length === 1) {
        return result[0]
    } else {
        return -1
    }
}

function dfs(start, initArr, preSum, result, map, count) {
    if(result.length > 1) {
        return
    }
    if(start >= initArr.length) {
        result.push(count)
        return;
    }

    for (let i = start; i < initArr.length ; i++) {
        let sum = preSum[i] -preSum[start] + initArr[i]

        if(map.has(sum) || valid(sum, map)) {
            dfs(i+1, initArr, preSum, result, map, count + 1)
        }
    }
}

function valid(num, map) {
    if(num < 100 || num > 999) return false;
    let [a, b, c] = num.toString().split("").map(Number)
    if(num === Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3)) {
        map.set(num, true)
        return  true
    }
    return  false
}








